<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('基金管理人') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
      <el-form-item :label="$t('管理人全称')" prop="name">
        <el-input
          v-model="queryParams.name"
          :placeholder="$t('管理人全称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('管理人简称')" prop="shortName">
        <el-input
          v-model="queryParams.shortName"
          :placeholder="$t('管理人简称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <!--<el-form-item :label="$t('管理人类型')" prop="type">
        <el-select v-model="queryParams.type" :placeholder="$t('管理人类型')" clearable>
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item :label="$t('机构类型')" prop="organizationType">
        <el-select v-model="queryParams.organizationType" :placeholder="$t('机构类型')" clearable>
          <el-option
            v-for="dict in organizationTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:gpbase:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:gpbase:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="gpBaseList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理人全称')" align="center" prop="name">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/fund/gpBase/gpBaseHome',query:{ id:scope.row.id, gpId: scope.row.id }}"
            class="link_a"
          >{{ scope.row.name }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理人简称')" align="center" prop="shortName" />
      <!--<el-table-column :label="$t('管理人类型')" align="center" prop="type" :formatter="typeFormat" show-overflow-tooltip width="120" />-->
      <el-table-column :label="$t('成立时间')" align="center" prop="timeEstablishment" show-overflow-tooltip width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.timeEstablishment) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('机构企业性质')" align="center" prop="natureEnterprise" :formatter="natureEnterpriseFormat" />
      <el-table-column :label="$t('机构类型')" align="center" prop="organizationType" :formatter="organizationTypeFormat" show-overflow-tooltip width="130" />
      <el-table-column :label="$t('机构组织形式')" align="center" prop="organizationForm" :formatter="organizationFormFormat" show-overflow-tooltip width="140" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['fund:gpbase:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['fund:gpbase:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改基金管理人对话框 -->
    <el-dialog :title="title" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <gpBaseForm ref="gpBaseForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listByBfManage, delGpBase, exportGpBase } from '@/api/fund/gp/gpBase'
import gpBaseForm from './gpBaseForm.vue'
export default {
    components: {
        gpBaseForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 基金管理人表格数据
          gpBaseList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
        // 管理人类型字典
        typeOptions: [],
        // 是否完成基金业协会登记日期字典
        isConsortiumRegistryOptions: [],
        // 机构企业性质字典
        natureEnterpriseOptions: [],
        // 机构类型字典
        organizationTypeOptions: [],
        // 机构组织形式字典
        organizationFormOptions: [],
          // 查询参数
          queryParams: {
              name: undefined,
              shortName: undefined,
              type: undefined,
              organizationType: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          }
      }
  },
  created() {
      this.getList()
      this.getDicts('fund_manger_type').then(response => {
          this.typeOptions = response.data
      })
      this.getDicts('sys_yes_no').then(response => {
          this.isConsortiumRegistryOptions = response.data
      })
      this.getDicts('manager_enterprise_nature').then(response => {
          this.natureEnterpriseOptions = response.data
      })
      this.getDicts('manager_type').then(response => {
          this.organizationTypeOptions = response.data
      })
      this.getDicts('manager_organizational form').then(response => {
          this.organizationFormOptions = response.data
      })
  },
  methods: {
    /** 查询基金管理人列表 */
    getList() {
        this.loading = true
        listByBfManage(this.queryParams).then(response => {
            this.gpBaseList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 管理人类型字典翻译
    typeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.typeOptions, row.type)
    },
    // 是否完成基金业协会登记日期日期字典翻译
    isConsortiumRegistryFormat(row) {
      return this.selectDictLabel(this.isConsortiumRegistryOptions, row.isConsortiumRegistry)
    },
    // 机构企业性质字典翻译
    natureEnterpriseFormat(row) {
      return this.selectDictLabel(this.natureEnterpriseOptions, row.natureEnterprise)
    },
    // 机构类型字典翻译
    organizationTypeFormat(row) {
      return this.selectDictLabel(this.organizationTypeOptions, row.organizationType)
    },
    // 机构组织形式字典翻译
    organizationFormFormat(row) {
      return this.selectDictLabel(this.organizationFormOptions, row.organizationForm)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            name: undefined,
            shortName: undefined,
            type: '0',
            isConsortiumRegistry: '0',
            dateRegistration: undefined,
            associationNumber: undefined,
            unifiedSocialCreditCode: undefined,
            legalRepresentative: undefined,
            documentType: undefined,
            certificateNo: undefined,
            timeEstablishment: undefined,
            natureEnterprise: undefined,
            organizationType: undefined,
            organizationForm: undefined,
            contacts: undefined,
            contactPerson: undefined,
            contactPhone: undefined,
            contactEmail: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.title = this.$t('基金管理人')
        this.$nextTick(() => {
            this.$refs.gpBaseForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = this.$t('基金管理人')
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.gpBaseForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delGpBase(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportGpBase(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    }
  }
}
</script>
